﻿using AntMovement.Core;
using AntMovement.Core.Attributes;
using AntMovement.Core.Entity;
using AntMovement.Core.Hardware;
using AntMovement.Core.IParameter;
using AntMovement.Core.Logic;
using AntMovement.Core.Logic.Base;
using AntMovement.Core.Model;
using AntMovement.Parameter;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AntMovement.Handle.TPTest
{
    [FlowAttributes(nameof(CacheLocation), 7)]
    public class CacheLocation : TaskBase
    {
        #region 轴变量
        #endregion

        #region 上升沿
        #endregion

        #region 定时器
        #endregion

        #region 点位
        #endregion

        #region 输入点
        private NormalOpen _缓存位真空信号;
        #endregion

        #region 输出点
        private ICoil _缓存位真空;
        #endregion

        #region 报警变量
        #endregion

        #region 私有变量
        #endregion

        public CacheLocation(ITemporaryParameter temporary, IIOParameter iop, IAxisParameter axisp, IDialogHost dialogHost, ILog log)
            : base(temporary, iop, axisp, dialogHost, log)
        {
            _缓存位真空信号 = iop.GetNormalOpen("缓存位真空信号");

            _缓存位真空 = iop.GetCoil("缓存位真空");
            _temporary.Status_缓存工位 = new StationStatusModel();
        }

        public override void EmergencyStop()
        {

        }

        public override void Handle()
        {
            if (SignalOn(0))
            {
                if (_缓存位真空信号.Execute())
                {
                    NextStep(20);
                }
                else
                {
                    if (_temporary.Status_缓存工位.SafetyPosition)
                    {
                        _temporary.Status_缓存工位.Permit_Blowing = true;
                        NextStep();
                    }
                }
            }
            if (SignalOn(10) && _temporary.Status_缓存工位.DischargeComplete)
            {
                _temporary.Status_缓存工位.DischargeComplete = false;
                _temporary.Status_缓存工位.Permit_Blowing = false;
                NextStep();
            }
            if (SignalOn(20))
            { 
                _temporary.Status_缓存工位.Permit_TakeMaterials = true;
                NextStep();
            }
            if (SignalOn(30) && _temporary.Status_缓存工位.WithdrawalComplete)
            {
                _temporary.Status_缓存工位.WithdrawalComplete = false;
                _step = 0;
            }
            if (_temporary.SystemStatus.ManualOperation)
            {

            }
        }

        public override void Resetting()
        {
            _temporary.Status_缓存工位.DischargeComplete = false;
            _temporary.Status_缓存工位.Permit_TakeMaterials = false;
            _temporary.Status_缓存工位.Permit_Blowing = false;
            _temporary.Status_缓存工位.WithdrawalComplete = false;
            _step = 0;
        }

        public override void SafeStop()
        {

        }
    }
}
